//
//  ViewController.m
//  WashForU
//
//  Created by 王俊 on 15/11/24.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "SplashController.h"

#import "UIColor+ExtUIColor.h"

@implementation SplashController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUpViews];
    [self addConstrains]; 
}

/*****************添加视图组件********************/
- (void)setUpViews
{
    _splModel = [SplashModel initFromImageNameSet:SPLASHIMAGE];
    _splView = [SplashView initWithModelData:_splModel];              //实例化一个scrollView
    _splView.delegate = self;
    [self.view addSubview: _splView];                                 //将scrollView加入视图
    
    _pgControl = [[UIPageControl alloc]init];
    _pgControl.numberOfPages = _splModel.imageNameSet.count;
    _pgControl.tintColor = [UIColor GrayColor_188];
    _pgControl.currentPageIndicatorTintColor = [UIColor CustomLightBlue];
    [self.view addSubview:_pgControl];
    
    _splButton = [[UIButton alloc]init];
    [_splButton setImage:[UIImage imageNamed:@"登录按钮"] forState: UIControlStateNormal];
    _splButton.hidden = true;
    [_splButton addTarget:self action:@selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_splButton];
}
/*******************添加约束**********************/
- (void)addConstrains
{
    [_splView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    [_pgControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(60, 30));
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-60);
    }];
    [_splButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(150, 35));
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.pgControl.mas_top);
    }];
}
/*****************监听scrollView动作*****************/
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _splButton.hidden = (_splView.contentOffset.x < (2 * SCREENWIDTH - 85)) ? true:false;
    _pgControl.currentPage = (int)(scrollView.contentOffset.x / SCREENWIDTH);    
}

/*****************登录Button点击事件*****************/
- (void)loginButtonClicked: (UIButton *)sender
{
    MainTabBarController *vc = [[MainTabBarController alloc]init];
    [self.navigationController pushViewController:vc animated:true];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}





@end
